//
//  CZMainTabbar.swift
//  swift微博01
//
//  Created by 张文文 on 15/12/16.
//  Copyright © 2015年 张文文. All rights reserved.
//

import UIKit

class CZMainTabbar: UITabBar {

    //属性 定义五个控制
    private let count = 5
    override func layoutSubviews() {
        super.layoutSubviews()
        let width = self.bounds.width / CGFloat(count)
        let height = self.bounds.height
        //设置最左边的frame
        let frame = CGRectMake(0, 0, width, height)
        
        var index = 0
        for view in self.subviews{
        
            if view is UIControl && !(view is UIButton){
            
                view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
                index += index == 1 ? 2 : 1
            }
        }
        composeButton.frame = CGRectOffset(frame, 2.0 * width, 0)
    }
    
    
    //懒加载自定义控件
    lazy var composeButton : UIButton = {
    
       let button = UIButton()
        //设置背景图片
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        //设置按钮图片
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        self.addSubview(button)
        return button
    }()
}
